# Operating System Detection for FPC

These can be used to detect the OS during compiling on Free Pascal and Lazarus.

One version is this one, looks elegant:

```pascal
  {$if defined(WINDOWS)}
  {$elseif defined(UNIX)}
    {$if defined(LINUX)}
    {$elseif defined(BSD)}
      {$if defined(DARWIN)} // MacOSX
      {$endif}
    {$endif}
  {$elseif defined(MAC)} // Classic Macs
  {$else}
  {$endif}
```

Another is this one, which is more common:

```pascal
  {$IFDEF WINDOWS}
  {$ENDIF}
  {$IFDEF UNIX}
    {$IFDEF LINUX}
    {$ENDIF}
    {$IFDEF BSD}
    {$IFDEF DARWIN} // MacOSX
    {$ENDIF}
    {$ENDIF}
  {$ENDIF}
  {$IFDEF MAC} // Classic Macs
  {$ENDIF}
```


Ref:
- https://wiki.freepascal.org/Conditional_compilation#.24ifdef_and_.24endif
- https://forum.lazarus.freepascal.org/index.php/topic,15869.msg85735.html?PHPSESSID=t78qvf8s0t8ag6sf79j40f53h7#msg85735